//
//  BaseTableViewController.swift
//  sinaweibowj
//
//  Created by Macintosh on 15/12/13.
//  Copyright © 2015年 mactoinsh. All rights reserved.
//

import UIKit

//根据用户是否登录去显示方可视图还是表视图
class BaseTableViewController: UITableViewController,VisitorLoginViewDelegate
{
    
    
    //社会自用户是否登录的标记
    var userLogin = UserAccountViewModel().userLogin
    
    //新建属性访客视图
    var visitorLoginView : VisitorLoginView?
    
    //如果检测到跟视图为nil，自动调用loadview、
    
    override func loadView() {
        
        if userLogin {
            
            //显示tableView
            super.loadView()
        }else {
            
            setVisitorLoginView()
        }
    }
    
    private func setVisitorLoginView() {
        
        visitorLoginView = VisitorLoginView()
        visitorLoginView?.visitorViewDelegate = self
        
        view = visitorLoginView
        
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "userWillRegister")
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "userWillLogin")
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        print(view.bounds)
    }
    
    func userWillRegister(){
    print(__FUNCTION__)
        
           }
    
    func userWillLogin(){
    print(__FUNCTION__)
        
        let OAuth = OAuthViewController()
        //添加到导航控制器视图
        let nav = UINavigationController(rootViewController: OAuth)
        presentViewController(nav, animated: true, completion: nil)
        

    }
}
